<template>
    <table>
   
       <tr>
           <td>房号</td>
           <td>
               <input type="text" v-model="info.RN_Num" placeholder="请输入房号">
           </td>
       </tr>
       <tr>
           <td>房号状态</td>
           <td>
               <input type="radio" v-model="info.RN_Status" :value="true">上架
               <input type="radio" v-model="info.RN_Status" :value="false">下架
           </td>
       </tr>
       <tr>
           <td>备注</td>
           <td>
               <textarea v-model="info.RN_BeiZhu" placeholder="请输入备注">
   
               </textarea>
           </td>
       </tr>
       <tr>
           <td></td>
           <td>
               <input type="button" value="修改房号" @click="save">
           </td>
       </tr>
     
    </table>
   </template>
   
   <script setup lang="ts">
   import {onMounted,ref} from 'vue'
   import { useRoute,useRouter } from 'vue-router';
   import axios from 'axios'
   import {useCounterStore} from '../../stores/counter.ts'
   
   const userstore=useCounterStore();
   
   const use=useRoute();
   const user=useRouter();
   
   const names=ref("")
   onMounted(()=>{
     
       fantian();
   })
   
   //修改字段
   const info=ref({
    "RN_Id": 1,
     "RN_Num": "",
     "RN_Status": true,
     "RN_BeiZhu": "",
     "RN_DateTime": "2024-12-06T04:42:59.128Z"
   })
   
   //判断当前用户是否为管理员
   const guanli=()=>{
     
       axios.get("https://localhost:7234/api/RoomInfo/GettypeByname",{
           params:{
               name:userstore.username
           }
       })
       .then(res=>{
           names.value=res.data
       })
   }
   //反填
   const fantian=()=>{
    axios.get("https://localhost:7234/api/RoomNumber/RoomNumberByid",{
        params:{
            id:use.params.id
        }
    })
    .then(res=>{
        info.value=res.data
    })
   }
   //添加
   const save=()=>{
    //    if(names.value!="管理员"){
    //        alert("对不起您无权限执行此操作");
    //        user.push("/Login")
    //        return;
    //    }
       if(info.value.RN_Num==""){
           alert("房号不能为空");
           return;
       }
       axios.put("https://localhost:7234/api/RoomNumber/UpdaRn",info.value)
       .then(res=>{
           if(res.data>0){
               alert("修改成功");
                   user.push("/ShowNumber")
           }else if(res.data==-1){
               alert("不允许重复添加")
           }else{
               alert("修改失败")
           }
       })
       
   }
   
   
   
   
   
   </script>
   
   <style scoped>
   
   </style>